<!DOCTYPE html>
<!-- 学生端首页 -->
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>教师主页</title>
    <style>
        .body {
            min-width: 1366px;
        }

        .app-main {
            height: calc(100% - 64px);
        }

        .app-main .divTmp {
            width: 100%;
            height: 100%;
        }
    </style>

    <!-- 引入样式和插件-->
    <link rel="shortcut icon" href="../../favicon.ico">
    <link rel="stylesheet" href="../../plugins/element-ui/index.css"/>
    <link rel="stylesheet" href="../../styles/common.css"/>
    <link rel="stylesheet" href="../../styles/index.css"/>
    <link rel="stylesheet" href="../../styles/icon/iconfont.css"/>
    <script src="../../plugins/vue/vue.js"></script>
    <script src="../../plugins/element-ui/index.js"></script>

</head>

<body>
<div class="app" id="app">
    <div class="app-wrapper openSidebar clearfix">
        <!-- sidebar -->
        <div class="sidebar-container">
            <!-- 左上角logo -->
            <div class="logo">
                <img src="../../images/login-logo.png" alt="" style="width: 120px; height: 50px"/>
            </div>

            <el-scrollbar wrap-class="scrollbar-wrapper">
                <!-- 最左侧 默认选择，是否单独展开，不知道，背景色，字体色-->
                <el-menu
                        :default-active="defAct"
                        :unique-opened="false"
                        :collapse-transition="false"
                        background-color="#3e0000"
                        text-color="#e5eeff"
                        active-text-color="#f4f4f5"
                >
                    <div v-for="item in menuList" :key="item.id">
                        <el-submenu :index="item.id" v-if="item.children && item.children.length>0">
                            <!-- 右侧 -->
                            <template slot="title">
                                <i class="iconfont" :class="item.icon"></i>
                                <span>{{item.name}}</span>
                            </template>
                            <el-menu-item
                                    v-for="sub in item.children"
                                    :index="sub.id"
                                    :key="sub.id"
                                    @click="menuHandle(sub,false)"
                            >
                                <i :class="iconfont" :class="sub.icon"></i>
                                <span slot="title">{{sub.name}}</span>
                            </el-menu-item
                            >
                        </el-submenu>
                        <!-- 左侧 -->
                        <el-menu-item v-else :index="item.id" @click="menuHandle(item,false)">
                            <i class="iconfont" :class="item.icon"></i>
                            <span slot="title">{{item.name}}</span>
                        </el-menu-item>
                    </div>
                </el-menu>
            </el-scrollbar>
        </div>
        <div class="main-container">
            <!-- <navbar /> -->
            <div class="navbar">
                <div class="head-lable">
              <span v-if="goBackFlag" class="goBack" @click="goBack()"
              ><img src="../../images/icons/btn_back@2x.png" alt=""/> 返回</span
              >
                    <span>{{headTitle}}</span>
                </div>
                <!-- 右侧 -->
                <div class="right-menu">
                    <div class="avatar-wrapper">教师：{{ userInfo.teacherClass }} {{ userInfo.teacherName }}</div>
                    <img src="../../images/icons/btn_close@2x.png" class="outLogin" alt="退出" @click="logout"/>
                </div>
            </div>
            <div class="app-main" v-loading="loading">
                <div class="divTmp" v-show="loading"></div>
                <!-- 让右侧动态加载，通过:src，下面有动态url -->
                <iframe
                        id="cIframe"
                        class="c_iframe"
                        name="cIframe"
                        :src="iframeUrl"
                        width="100%"
                        height="auto"
                        frameborder="0"
                        v-show="!loading"
                ></iframe>
            </div>
        </div>
    </div>
</div>

<script>
    new Vue({
        el: '#app',
        data() {
            return {
                defAct: '1',
                menuActived: '1',
                userInfo: {},
                menuList: [
                    {
                        id: '1',
                        name: '学生管理',
                        url: 'studentManage.html'
                    },
                    {
                        id: '2',
                        name: '消息管理',
                        url: 'message.html'
                    },
                    {
                        id: '3',
                        name: '发布实验',
                        url: 'report.html'
                    },
                    {
                        id: '4',
                        name: '批改报告',
                        url: 'score.html'
                    },
                    {
                        id: '5',
                        name: '修改密码',
                        url: 'password.html'
                    }
                ],
                // 默认选择右侧的页面
                iframeUrl: 'studentManage.html',
                // 默认上面标题
                headTitle: '学生管理',
                goBackFlag: false,
                loading: true,
                timer: null
            }
        },
        computed: {},
        created() {
            const userInfo = window.localStorage.getItem('userInfo')
            if (userInfo) {
                this.userInfo = JSON.parse(userInfo)
            }
            this.closeLoading()
        },
        beforeDestroy() {
            this.timer = null
            clearTimeout(this.timer)
        },
        mounted() {
            window.menuHandle = this.menuHandle
        },
        methods: {
            logout() {
                localStorage.removeItem('userInfo')
                window.location.href = '../../index.html'
            },
            goBack() {
                // window.location.href = 'javascript:history.go(-1)'
                const menu = this.menuList.find(item => item.id === this.menuActived)
                // this.goBackFlag = false
                // this.headTitle = menu.name
                this.menuHandle(menu, false)
            },
            menuHandle(item, goBackFlag) {
                this.loading = true
                this.menuActived = item.id
                this.iframeUrl = item.url
                this.headTitle = item.name
                this.goBackFlag = goBackFlag
                this.closeLoading()
            },
            closeLoading() {
                this.timer = null
                this.timer = setTimeout(() => {
                    this.loading = false
                }, 1000)
            }
        }
    })
</script>
</body>
</html>
